package thread;

public class Bank
{
    private int account = 20000;
    public synchronized boolean  getMoney(int money)
    {
        int account = getAccount();
        if (account >= money)
        {
            account = account - money;
            Thread.yield();    // 主动让出时间片
            saveAccount(account);
            return true;
        }
        return false;
    }

    public int getAccount()
    {
        return this.account;
    }

    public void saveAccount(int account)
    {
        this.account = account;
    }

}
